package me.zhengjie.controller.merge;

import me.zhengjie.controller.test.DropGoodTest;
import me.zhengjie.dao.MergeTaskDao;
import me.zhengjie.enums.ConstantStatus;
import me.zhengjie.vo.Result;
import me.zhengjie.vo.wcs.ResponseTaskToWcsVo;
import org.springframework.web.client.RestTemplate;

public class MergeTest {

    public static void TestOutMergeTask(MergeTaskDao mergeTaskDao) {
        RestTemplate restTemplate = new RestTemplate();
        String requestURL = "http://localhost:8080/pickPlace/task";

        // 调用出库取货逻辑
        ResponseTaskToWcsVo responseTaskToWcsVo0 = DropGoodTest.outboundPickTask(
                mergeTaskDao.getTaskId(),
                mergeTaskDao.getTaskStart(),
                mergeTaskDao.getContainerCode(),
                false, 1, 2, ConstantStatus.Merge_OutBound_Type);
        Result<?> responseResult0 = restTemplate.postForObject(requestURL, responseTaskToWcsVo0, Result.class);
        if (responseResult0 == null || responseResult0.getCode() != 200) {
            System.out.println("调用开始出库取货逻辑失误" + mergeTaskDao.getTaskId());
            throw new RuntimeException("调用开始出库取货逻辑失误");
        }


        // 调用出库放货逻辑
        ResponseTaskToWcsVo responseTaskToWcsVo1 = DropGoodTest.outboundPickTask(
                mergeTaskDao.getTaskId(),
                mergeTaskDao.getTaskEnd(),
                mergeTaskDao.getContainerCode(),
                false, 2, 2, ConstantStatus.Merge_OutBound_Type);
        Result<?> responseResult1 = restTemplate.postForObject(requestURL, responseTaskToWcsVo1, Result.class);
        if (responseResult1 == null || responseResult1.getCode() != 200) {
            System.out.println("调用完成出库取货逻辑失误" + mergeTaskDao.getTaskId());
            throw new RuntimeException("调用开始出库取货逻辑失误");
        }
    }

    public static void TestInMergeTask(MergeTaskDao mergeTaskDao) {
        RestTemplate restTemplate = new RestTemplate();
        String requestURL = "http://localhost:8080/pickPlace/task";

        // 调用回库取货逻辑
        ResponseTaskToWcsVo responseTaskToWcsVo0 = DropGoodTest.outboundPickTask(
                mergeTaskDao.getTaskId(),
                mergeTaskDao.getTaskStart(),
                mergeTaskDao.getContainerCode(),
                false, 1, 1, ConstantStatus.Merge_RetBound_Type);
        Result<?> responseResult0 = restTemplate.postForObject(requestURL, responseTaskToWcsVo0, Result.class);
        if (responseResult0 == null || responseResult0.getCode() != 200) {
            System.out.println("调用开始入库取货逻辑失误" + mergeTaskDao.getTaskId());
            throw new RuntimeException("调用开始入库取货逻辑失误");
        }


        // 调用回库放货逻辑
        ResponseTaskToWcsVo responseTaskToWcsVo1 = DropGoodTest.outboundPickTask(
                mergeTaskDao.getTaskId(),
                mergeTaskDao.getTaskEnd(),
                mergeTaskDao.getContainerCode(),
                false, 2, 1, ConstantStatus.Merge_RetBound_Type);
        Result<?> responseResult1 = restTemplate.postForObject(requestURL, responseTaskToWcsVo1, Result.class);
        if (responseResult1 == null || responseResult1.getCode() != 200) {
            System.out.println("调用开始入库取货逻辑失误" + mergeTaskDao.getTaskId());
            throw new RuntimeException("调用开始入库取货逻辑失误");
        }
    }

}
